<form ng-if="applicationState.endpoint.apiVersion >= 1.3" id="service-configs" ng-submit="updateService(service)">
  <rd-widget>
    <rd-widget-header icon="list" title-text="Configs"> </rd-widget-header>
    <rd-widget-body classes="no-padding">
      <div class="form-inline" style="padding: 10px" authorization="DockerServiceUpdate">
        Add a config:
        <select
          class="form-control !h-[30px] !text-[13px]"
          ng-options="config.Name for config in filterConfigs(configs) | orderBy: 'Name'"
          ng-model="newConfig"
          data-cy="service-configs-select"
        >
          <option selected disabled hidden value="">Select a config</option>
        </select>
        <a class="btn btn-default btn-sm" ng-click="addConfig(service, newConfig)"> <pr-icon icon="'plus'"></pr-icon> add config </a>
      </div>
      <table class="table" style="margin-top: 5px">
        <thead>
          <tr>
            <th>Name</th>
            <th>Path in container</th>
            <th>UID</th>
            <th>GID</th>
            <th>Mode</th>
            <th></th>
          </tr>
        </thead>
        <tbody>
          <tr ng-repeat="config in service.ServiceConfigs">
            <td>
              <a ui-sref="docker.configs.config({id: config.Id})">{{ config.Name }}</a>
            </td>
            <td ng-if="!config.credSpec">
              <input
                class="form-control"
                ng-model="config.FileName"
                ng-change="updateConfig(service)"
                placeholder="e.g. /path/in/container"
                required
                disable-authorization="DockerServiceUpdate"
                ng-disabled="config.credSpec"
              />
            </td>
            <td ng-if="!config.credSpec">{{ config.Uid }}</td>
            <td ng-if="!config.credSpec">{{ config.Gid }}</td>
            <td ng-if="!config.credSpec">{{ config.Mode }}</td>
            <td ng-if="config.credSpec" colspan="4">Credential Spec</td>
            <td authorization="DockerServiceUpdate">
              <button class="btn btn-dangerlight pull-right" type="button" ng-click="removeConfig(service, $index)" ng-disabled="isUpdating">
                <pr-icon icon="'trash-2'" size="'md'"></pr-icon>
              </button>
            </td>
          </tr>
          <tr ng-if="service.ServiceConfigs.length === 0">
            <td colspan="6" class="text-muted text-center">No configs associated to this service.</td>
          </tr>
        </tbody>
      </table>
    </rd-widget-body>
    <rd-widget-footer authorization="DockerServiceUpdate">
      <div class="btn-toolbar" role="toolbar">
        <div class="btn-group" role="group">
          <button type="submit" class="btn btn-primary btn-sm" ng-disabled="!hasChanges(service, ['ServiceConfigs'])">Apply changes</button>
          <button type="button" class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
            <pr-icon icon="'chevron-down'"></pr-icon>
          </button>
          <ul class="dropdown-menu">
            <li><a ng-click="cancelChanges(service, ['ServiceConfigs'])">Reset changes</a></li>
            <li><a ng-click="cancelChanges(service)">Reset all changes</a></li>
          </ul>
        </div>
      </div>
    </rd-widget-footer>
  </rd-widget>
</form>
